var userCenterPage = avalon.define({
	$id: "userCenterPage",
	uid: "",
	name: "Click to login",
	favNum: 0,
	integralNum:0,
	couponNum:0,
	status: 0,
	roleId: -1,
	signCustomerId: "",
	level:'0',
	parentId:'',
	integralOpen:''
});

mui.ready(function() {
	userCenterPage.name=$.i18n.prop('User_Center_Click_to_login');
	var uid = $("#uid").val();
	userCenterPage.uid = uid;

	if("" != uid) {
		mui.ajax('/user/get.json', {
			data: {
				uid: userCenterPage.uid
			},
			dataType: 'json',
			success: function(data) {
				if(""!=data&&null!=data){
					userCenterPage.status = data.status;
					userCenterPage.name = data.name;
					userCenterPage.roleId = data.role.id;
					userCenterPage.signCustomerId = data.signCustomerId;
					userCenterPage.integralNum=data.customer.integral;
					userCenterPage.level=data.customer.level;
					userCenterPage.parentId=data.customer.parentId;
					userCenterPage.integralOpen=data.customer.integralOpen;
					i18nReady();
				}
			}
		});
	}

	mui(".no-logon").on('tap', '.userName', function() {
		
		//本地开发
//		logon("13932419368211185668");
//		var url = "user.html";
		//生产
		var url = "dahua://login";
		mui.openWindow({
			url: url 
		});
	});
	
	mui(".logout").on('tap', 'li', function() {
		//本地开发
		//logout();
		//var url = "user.html";
		
		//生产
		var url = "dahua://logout";
		mui.openWindow({
			url: url 
		});
	});

	mui(".user").on('tap', 'a', function() {
		var url = "";
        if(this.getAttribute('href')!="#" && $(this).hasClass('valid'))
        {
            if("" == userCenterPage.uid) {
                url = "dahua://login";
            } else {
                if(2 == userCenterPage.status || 3 == userCenterPage.status) {
                    url = "dahua://logout";
                } else {
                    url = this.getAttribute('href');
                }
            }
        }else {
			url = this.getAttribute('href');
		}
		mui.openWindow({
			url: url
		});
	});

});
